package de.hsbremen.dirtybox;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ContactsActivity  extends Activity {
	String name, phone;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.contacts);

		Toast.makeText(ContactsActivity.this, "CreateContacts", 10).show();
		final Cursor cursor = getContentResolver().query(
				ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
				null, null, null, null);
		final StringBuffer buffer = new StringBuffer();
		
		if(cursor.moveToFirst()) {
		   final int nameIdx = cursor.getColumnIndexOrThrow(
				ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
			 final int phoneIdx = cursor.getColumnIndexOrThrow(
				ContactsContract.CommonDataKinds.Phone.NUMBER);
			 do {
		       name = cursor.getString(nameIdx);
		       phone = cursor.getString(phoneIdx);
		       buffer.append("Name: " + name + 
				    "\nNummer: " + phone + "\n\n");
		       TextView tv = new TextView(ContactsActivity.this);
		       tv.setText(name + phone);
		       ((LinearLayout) findViewById(R.id.contact_list)).addView(tv);
		    } while (cursor.moveToNext());
		}
		
		cursor.close();
	}
}
